<template>
  <div class="app-container">

    <el-row :gutter="20" style="height: 800px">
      <!--用户数据-->
      <el-card class="box-card" style="width: 500px; float: left; height: 560px">
        <div slot="header" class="clearfix">
          <span>贷款的学生</span>
          <el-button style="float: right; padding: 3px 0" @click="resetQuery" type="text">重置</el-button>
        </div>
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="130px">
          <el-form-item prop="phonenumber" label="请输入机号码搜索">
            <el-input
              v-model="queryParams.phonenumber"
              placeholder="请输入手机号码"
              clearable
              size="small"
              style="width: 210px"
              @keyup.enter.native="handleQuery"
            />
            <el-button style="margin-left: 20px" type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-form-item>
        </el-form>

        <el-col :span="24" :xs="24" style="float: left">

          <div slot="header" class="clearfix">
            <span>贷款的学生</span>
            <el-button style="float: right; padding: 3px 0" @click="resetQuery" type="text">重置</el-button>
          </div>
          <el-table @row-click="rowClick" :cell-style="{padding:'10px'}" v-loading="loading" :data="userList">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="学生姓名" prop="userName" width="120" align="center" />
            <el-table-column label="学生昵称" align="center" prop="nickName" />
            <el-table-column label="手机号码" align="center" prop="phonenumber" width="180" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="200">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-col>
      </el-card>

      <el-card class="box-card" style="width: 500px; float: left; height: 360px; margin-left: 20px">
        <div slot="header" class="clearfix">
          <span>学生贷款数据</span>
          <el-button style="float: right; padding: 3px 0" @click="resetQuery" type="text">重置</el-button>
        </div>
        <el-table v-loading="loading" :data="extendList" @selection-change="handleSelectionChange">
        <el-table-column width="120" label="年度" align="center" prop="duringYear" />
        <el-table-column width="120" label="借款年份" align="center" prop="contract.borrowYear" />
        <el-table-column width="120" label="账户名称" align="center" prop="contract.accountName" />
        <el-table-column width="120" label="借款有限时间内" align="center" prop="contract.borrowLimitYear" />
        <el-table-column width="180" label="贷款开始时间" align="center" prop="birth" >
          <el-table-column width="60" label="年" align="center" prop="contract.didYear" />
          <el-table-column width="60" label="月" align="center" prop="contract.didMonth" />
          <el-table-column width="60" label="日" align="center" prop="contract.didDay" />
        </el-table-column>
        <el-table-column width="120" label="贷款期限到后有限天数" align="center" prop="contract.countDay" />
        <el-table-column width="120" label="贷款期限到后不能超过几天" align="center" prop="contract.expireDay" />
        <el-table-column width="120" label="出生日期" align="center" prop="birth" />
        <el-table-column width="180" label="学生身份证" align="center" prop="cardIdentity" />
        <el-table-column width="120" label="户口性质" align="center" prop="residence" />
        <el-table-column width="120" label="毕业中学" align="center" prop="medium" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="户籍" align="center" prop="household" :show-overflow-tooltip="true" />
        <el-table-column width="200" label="通讯地址" align="center" prop="address" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="邮编" align="center" prop="postcode" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="申贷原因" align="center" prop="applyReason" :show-overflow-tooltip="true" />
        <el-table-column width="180" label="学生身份证有效起始日期" align="center" prop="studentEffectiveCardIdentity">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.studentEffectiveCardIdentity) }}</span>
          </template>
        </el-table-column>
        <el-table-column width="180" label="学生身份证有效结束日期" align="center" prop="studentInvalidCardIdentity" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.studentInvalidCardIdentity) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否展期" prop="contract.isExtended" align="center" fixed="right" width="140" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button slot="reference" size="small" :type="scope.row.contract.isExtended === '已通过' ? 'success' :  scope.row.contract.isExtended === '申请展期中' ?  'primary' : 'info'">{{ scope.row.contract.isExtended === '已通过' ? '展期待县审核中' : scope.row.contract.isExtended === '申请展期中' ? '展期待县审核中' : '是' }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      </el-card>
    </el-row>

  </div>
</template>

<script>
  import { listData, getData, delData, exportData } from "@/api/county/credit";
  import { getUserProfile } from "@/api/system/user";
  import { updateData } from '../../../api/hsien/contract'
  import { selectUserListForStudent } from '../../../api/system/user'
  import { getCredits } from '../../../api/county/credit'

  export default {
    data() {
      return {
        extendList: [],
        dialogVisible: false,
        user: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 学生数据
        userList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据学生贷款
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 6,
          creditName: undefined,
          userName: undefined,
          duringYear: undefined
        },
        // 表单参数
        form: {},
        // 合同表单参数
        contract: {},
        // 表单校验
        rules: {
          creditLabel: [
            { required: true, message: "数据标签不能为空", trigger: "blur" }
          ],
          creditValue: [
            { required: true, message: "数据键值不能为空", trigger: "blur" }
          ],
          creditSort: [
            { required: true, message: "数据顺序不能为空", trigger: "blur" }
          ]
        },
      };
    },
    created() {
      this.getList()
      this.getUser()
    },
    methods: {
      getUser() {
        getUserProfile().then(response => {
          this.user = response.data;
        });
      },
      rowClick(data) {
        getCredits(data.userName).then(response => {
          console.log(response)
          this.extendList = response.data
        })
      },
      /** 查询用户列表 */
      getList() {
        this.loading = true;
        //listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        selectUserListForStudent().then(response => {
          this.userList = response.userListForStudent;
          console.log(response)
          this.total = response.userListForStudent.length;
          this.loading = false;
        })
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          creditId: undefined,
          duringYear: undefined,
          qq: undefined,
          birth: undefined,
          cardIdentity: undefined,
          residence: undefined,
          medium: undefined, household: undefined,
          email: undefined, address: undefined, postcode: undefined,
          guarantor: undefined, guaPhone: undefined, relation: undefined,
          guaCardIdentity: undefined, heath: undefined,
          applyReason: undefined, signatureDate: undefined, countyUnit: undefined,
          isSeal: undefined, sealDate: undefined, studentEffectiveCardIdentity: undefined,
          studentInvalidCardIdentity: undefined, supportCenterProvince: undefined,
          supportCenterCity: undefined, supportCenterArea: undefined,
          householdOfProvince: undefined, householdOfCity: undefined,
          householdOfArea: undefined, householdOfCounty: undefined,
          householdOfDetail: undefined, homeOfProvince: undefined,
          homeOfCity: undefined, homeOfArea: undefined, homeOfCounty: undefined,
          homeOfDetail: undefined, isTheSameAsHousehold: undefined,
          homeOfPostcode: undefined, homeOfPhone: undefined, concatOfName: undefined,
          concatWorkUnit: undefined, concatOfPhone: undefined, concatOfCardIdentity: undefined,
          collegeOfName: undefined, collegeOfInstitute: undefined,
          collegeOfMajor: undefined, collegeOfEducation: undefined,
          collegeWithStart: undefined, studentNo: undefined, typeOfMajor: undefined,
          collegeOfEducationalSystem: undefined,
          collegeWithEnd: undefined, workUnit: undefined, workFeature: undefined,
          phoneOfUnit: undefined, postcodeOfUnit: undefined, addressOfUnit: undefined,
          changeForReason: undefined,
          identityPathOfFront: undefined,
          identityPathOfReverse: undefined,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加学生贷款数据";
        this.form.userName = this.queryParams.userName;
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.creditId)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const creditId = row.creditId || this.ids
        getData(creditId).then(response => {
          this.form = response.data;
        });
      },
      /** 提交按钮 */
      submitForm: function(row) {
        this.contract = row.contract
        this.contract.isExtended = '已通过'
        updateData(this.contract).then(res => {
          this.msgSuccess('该展期审核通过!')
          this.getList();
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const creditIds = row.creditId || this.ids;
        this.$confirm('是否确认删除学生贷款编码为"' + creditIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delData(creditIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportData(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      },
    },
  };
</script>
